﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="dokumendidVastusType", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(DokumendidVastusType))]
    public class DokumendidVastusTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDokumendidVastusType clazz;
        
        public DokumendidVastusTypeSerializer(IDokumendidVastusType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("DOKUMENDID");
            if (clazz.DOKUMENDID!=null) {
                global::Xtee.Core.SerializationMetadata metaDOKUMENDID = this.GetMetaData(clazz.DOKUMENDID);
                Writer.WriteTypeAttribute(metaDOKUMENDID.TypeQualifiedName.Namespace, metaDOKUMENDID.TypeQualifiedName.Name);
                metaDOKUMENDID.NewSerializer(clazz.DOKUMENDID).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DOKUMENDID");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="DOKUMENDID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>dokumendidVastusType>DOKUMENDID");
                }
                global::Xtee.Core.SerializationMetadata metaDOKUMENDID = this.GetMetaData<global::Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr.IDokumendid>(Reader, "dokumendid", "http://producers.ehr.xtee.riik.ee/producer/ehr");
                clazz.DOKUMENDID = metaDOKUMENDID.NewEntity<global::Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr.IDokumendid>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("DOKUMENDID");
                    metaDOKUMENDID.NewSerializer(clazz.DOKUMENDID).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>dokumendidVastusType>DOKUMENDID", Reader.LocalName);
            }
        }
    }
}
